<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<tiles:insertDefinition name="defaultTemplate">
    <tiles:putAttribute name="content">
        <h2 class="page-header">${book.title} <span class="title-date">(<fmt:formatDate value="${book.wrote}"
                                                                                        pattern="yyyy"/>)</span></h2>

        <div class="book-description">
            <img src="${contextPath}/resources/librry/books/covers/${book.cover}"
                 title="${book.title}" class="book-picture">
            <ul class="book-data">
                <li class="book-data-element">
                    <span class="book-data-list-title">Title</span>
                    <span class="book-data-list-data">${book.title}</span>
                </li>
                <li class="book-data-element">
                    <span class="book-data-list-title">Author</span>
                    <span class="book-data-list-data">${book.author.firstName} ${book.author.lastName}</span>
                </li>
                <li class="book-data-element">
                    <span class="book-data-list-title">Year</span>
                    <span class="book-data-list-data">(<fmt:formatDate value="${book.wrote}" pattern="yyyy"/>)</span>
                </li>
                <li class="book-data-element">
                    <span class="book-data-list-title">Uploader</span>
                    <span class="book-data-list-data">${book.user.username}</span>
                </li>
                <li class="book-data-element">
                        <%--<span class="book-data-list-title">Genre</span>--%>
                    <span class="book-data-list-data"><a
                            href="${contextPath}/resources/librry/books/files/${book.filepath}">Download</a></span>
                </li>
            </ul>
        </div>
        <div class="comments">
            <c:if test="${user!=null}">
                <form class="new-comment" action="/librry/book/${book.bookId}/comment" method="post">
                    <textarea class="new-comment-text" name="content" rows="3" cols="60">
                    </textarea>
                    <button type="submit" class="new-comment-submit">Post a comment</button>
                </form>
            </c:if>
            <h2>Comments :</h2>
            <div class="comment-list">
                <c:forEach items="${book.comments}" var="comm">
                    <div class="single-comment">
                        <img class="comment-image" src="${contextPath}/resources/images/user.png">

                        <div class="comment-body">
                            <a href="#" class="comment-author">${comm.user.username} - <fmt:formatDate
                                    value="${comm.created}"
                                    pattern="dd-MM-yyyy hh:mm"/></a>

                            <div class="comment">${comm.content}</div>
                        </div>
                    </div>
                </c:forEach>
            </div>
        </div>
    </tiles:putAttribute>
    <tiles:putAttribute name="popup">
        <br>
    </tiles:putAttribute>
</tiles:insertDefinition>